import axios from "axios";
// import {Toast} from 'vant'

const instance = axios.create({
    baseURL: 'https://www.liulongbin.top:8888/api/private/v1',
    // headers: {
    //     'Authorization':localStorage.getItem('adminToken')
    // }
});

instance.interceptors.request.use(function (config) {
    //在发送之前做些什么
    if (localStorage.getItem('adminToken')) {
        config.headers['Authorization'] = `${localStorage.getItem('adminToken')}`
    }
    return config;
}, function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
});
instance.interceptors.response.use(function (response) {
    // 对响应数据做点什么
    // toast.clear();
    return response;
}, function (error) {
    // 对响应错误做点什么
    return Promise.reject(error);
});


export function myAxios(Type, urls, Promise) {
    switch (Type) {
        case "GET":
            return httpGit(urls, Promise);
        case "POST":
            return httpPost(urls, Promise)
        case "PUT":
            return httpPut(urls, Promise)
        case "DELETE":
            return httpDelete(urls, Promise)
    }
}


function httpGit(urls, Promise) {
    return instance.get(urls, Promise)
}

function httpPost(urls, Promise) {
    return instance.post(urls, Promise)
}

function httpPut(urls, Promise) {
    return instance.put(urls, Promise)
}

function httpDelete(urls, Promise) {
    return instance.delete(urls, Promise)
}